/*
 * @Author: 徐汉卿 xuhanqing@imohoo.com
 * @Date: 2023-07-17 18:07:19
 * @LastEditors: 徐汉卿 xuhanqing@imohoo.com
 * @LastEditTime: 2023-08-31 11:12:05
 * @FilePath: /sy-app2/src/app.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { computed, createApp, watch } from "vue";
import { createPinia } from "pinia";
import "./app.scss";
import httpService from "./service/httpService";
import { noticeStore } from "@/store/notice";
import Taro from "@tarojs/taro";
import { useUserStore } from "./store/user";
import { Swiper, SwiperItem } from '@nutui/nutui-taro';
import { Input } from '@nutui/nutui';

const App = createApp({
  onShow(options) {


    Taro.hideHomeButton()
    const f1 = () => {
      if (useUserStore().getToken) {
        const fetchData = async () => {
          const res = await httpService.get("/api/XTRF/Notice/GetNotice", {});
          if (res.code === 0) {
            noticeStore().setData(res.result.type3);
            console.log("props123", res);
          }
        };

        fetchData();
      }
    };

    console.log("props123", "onShow");
    let user = computed(() => {
      return useUserStore().getToken;
    });

    //这有这样才能观察
    watch(
      user,
      (value) => {
        console.log("观察token", value);
        if (value) {
          console.log("xhq登录了");
          f1();
        } else {
          console.log("xhq退出了");
        }
      },
      { immediate: true }
    );

    setInterval(() => {
      f1();
    }, 30 * 1000);
  },
  // 入口组件不需要实现 render 方法，即使实现了也会被 taro 所覆盖
});
// Pinia状态管理
App.use(createPinia());
App.use(Swiper);
App.use(SwiperItem);
App.use(Input);
export default App;
